package health.lm.com.mine.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.androidkun.xtablayout.XTabLayout;
import com.lm.sjy.titlebar.widget.CommonTitleBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import health.lm.com.component_base.base.adapter.BaseFragmentAdapter;
import health.lm.com.component_base.base.mvp.activity.XActivity;
import health.lm.com.mine.R;
import health.lm.com.mine.R2;
import health.lm.com.mine.fragment.MyActivitiesItemFragment;
import health.lm.com.router.ARouterConstant;

import static com.lm.sjy.titlebar.widget.CommonTitleBar.ACTION_LEFT_BUTTON;

/**
 * 我的活动
 *
 * @author GQI
 * */
@Route(path = ARouterConstant.MyActivitiesActivity)
public class MyActivitiesActivity extends XActivity{
    @BindView(R2.id.title_bar)
    CommonTitleBar titlebar;
    @BindView(R2.id.xTablayout)
    XTabLayout xTablayout;
    @BindView(R2.id.viewPager)
    ViewPager viewPager;
    List<Fragment> fragments = new ArrayList<>();
    private String id[] = {"1","2"};

    @Override
    public int getLayoutId() {
        return R.layout.activity_my_activities;
    }

    @Override
    public Object newP() {
        return null;
    }

    @Override
    public void initData(Bundle savedInstanceState) {

        titlebar.setListener((v, action, extra) -> {
            if(action == ACTION_LEFT_BUTTON){
                finish();
            }
        });
        initViewPager();
    }

    private void initViewPager() {
        List<String> titles = new ArrayList<>();
        titles.add("参加的");
        titles.add("举办的");
        for (int i = 0; i < titles.size(); i++) {
            fragments.add( MyActivitiesItemFragment.getInstance(id[i]));
        }
        BaseFragmentAdapter adatper = new BaseFragmentAdapter(getSupportFragmentManager(), fragments, titles);
        viewPager.setAdapter(adatper);
        viewPager.setOffscreenPageLimit(2);
        //将TabLayout和ViewPager关联起来。
        xTablayout.setupWithViewPager(viewPager);
        //给TabLayout设置适配器
        xTablayout.setupWithViewPager(viewPager);

    }

}
